//
//  MyViewController.m
//  大轮胎
//
//  Created by 朱永超 on 2017/3/16.
//  Copyright © 2017年 zyc. All rights reserved.
//

//asdasd

#import "MyViewController.h"
static NSString *idfer=@"标识";
#import "PersonalView.h"
#import "LoginViewController.h"
#import <SDAutoLayout.h>
@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    PersonalView *personalView;
    UITableViewCell *cell;
}

@property (nonatomic,strong) UITableView *theTable;
// 表格头视图
@property (nonatomic,strong) UIView *headView;
// 头像按钮
@property (nonatomic,strong) UIButton *imgButton;
// 登录按钮
@property (nonatomic,strong) UIButton *loginButton;
// 设置按钮
@property (nonatomic,strong) UIButton *setButton;
// 购物车按钮
@property (nonatomic,strong) UIButton *shoppingButton;
@end

@implementation MyViewController
// 表格
-(UITableView *)theTable{
    if (!_theTable) {
        _theTable=[[UITableView alloc]initWithFrame:CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height) ];
    }
    _theTable.delegate=self;
    _theTable.dataSource=self;
    return _theTable;
}

-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden=YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor=[UIColor whiteColor];

    [self biaoqian];
    [self.view addSubview:self.theTable];

    [self.headView addSubview:self.imgButton];
    [self.headView addSubview:self.loginButton];
    [self.headView addSubview:self.setButton];
    [self.headView addSubview:self.shoppingButton];
    self.theTable.tableHeaderView=self.headView;
   
}
-(void)biaoqian{
    // 头视图
    _headView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 246)];
    _headView.backgroundColor=[UIColor colorWithRed:(253/255.0) green:(113/255.0) blue:(46/255.0) alpha:1];
    //  头像按钮
    _imgButton=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-50, 70, 100, 100)];
    _imgButton.layer.cornerRadius=50;
    _imgButton.layer.masksToBounds=YES;
    [_imgButton setImage:[UIImage imageNamed:@"设施小猫.png"] forState:0];
    _imgButton.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [_imgButton addTarget:self action:@selector(imag) forControlEvents:UIControlEventTouchUpInside];
    //  登录按钮
    _loginButton=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-80, 190, 150, 30)];
    [_loginButton setTitle:@"登 录   /   注 册" forState:0];
    [_loginButton.titleLabel setFont:[UIFont systemFontOfSize:20]];
    [_loginButton addTarget:self action:@selector(dengluu) forControlEvents:UIControlEventTouchUpInside];
    // 设置按钮
    _setButton=[[UIButton alloc]initWithFrame:CGRectMake(20, 30, 30, 30)];
    [_setButton setImage:[UIImage imageNamed:@"设置-3.png"] forState:UIControlStateNormal];
    [_setButton addTarget:self action:@selector(shezhi) forControlEvents:UIControlEventTouchUpInside];
    // 购物车按钮
    _shoppingButton=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-50, 30, 30, 30)];
    [_shoppingButton setImage:[UIImage imageNamed:@"购物.png"] forState:UIControlStateNormal];
    [_shoppingButton addTarget:self action:@selector(gouwuche) forControlEvents:UIControlEventTouchUpInside];
}
-(void)imag{
    
    LoginViewController *lodinVC=[[LoginViewController alloc]init];
    [self presentViewController:lodinVC animated:YES completion:^{
    }];
    
}
-(void)dengluu{
    
}
-(void)shezhi{
    
}
-(void)gouwuche{
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==1) {

        return 1;
    }
    else
    return 2;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return 0;
    }
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            return 70;
        }
    }
    return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    cell =[tableView dequeueReusableCellWithIdentifier:idfer];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:idfer];
    }
    if (indexPath.section==0) {
        if (indexPath.row==0) {

            
            
            UIButton * but = [[UIButton alloc]init];
           // but.backgroundColor = [UIColor redColor];
            [but setImage:[UIImage imageNamed:@"代付款"] forState:0];
            [cell.contentView addSubview:but];
            but.sd_layout
            .topSpaceToView(cell.contentView,5)
            .leftSpaceToView(cell.contentView,20)
            .widthIs((self.view.frame.size.width-100)/4)
            .heightIs(40);
            
            
            UIButton * but1 = [[UIButton alloc]init];
            // but.backgroundColor = [UIColor redColor];
            [but1 setImage:[UIImage imageNamed:@"代发货"] forState:0];
            [cell.contentView addSubview:but1];
            but1.sd_layout
            .topEqualToView(but)
            .leftSpaceToView(but,20)
            .widthIs((self.view.frame.size.width-100)/4)
            .heightIs(40);
            
            
            UIButton * but2 = [[UIButton alloc]init];
            [but2 setImage:[UIImage imageNamed:@"待收货"] forState:0];
            [cell.contentView addSubview:but2];
            but2.sd_layout
            .topEqualToView(but)
            .leftSpaceToView(but1,20)
            .widthIs((self.view.frame.size.width-100)/4)
            .heightIs(40);
            
            
            UIButton * but3 = [[UIButton alloc]init];
            [but3 setImage:[UIImage imageNamed:@"待评价"] forState:0];
            [cell.contentView addSubview:but3];
            but3.sd_layout
            .topEqualToView(but)
            .rightSpaceToView(cell.contentView,20)
            .widthIs((self.view.frame.size.width-100)/4)
            .heightIs(40);
            
            UILabel * lab = [[UILabel alloc]init];
            lab.text = @"待付款";
            lab.textAlignment = 1;
            lab.font = [UIFont systemFontOfSize:15];
            [cell.contentView addSubview:lab];
            
            lab.sd_layout
            .topSpaceToView(but,0)
            .leftEqualToView(but)
            .widthIs((self.view.frame.size.width-100)/4)
            .heightIs(20);
            
            UILabel * lab1 = [[UILabel alloc]init];
            lab1.text = @"待发货";
            lab1.textAlignment = 1;
            lab1.font = [UIFont systemFontOfSize:15];
            [cell.contentView addSubview:lab1];
            
            lab1.sd_layout
            .topSpaceToView(but,0)
            .leftEqualToView(but1)
            .widthIs((self.view.frame.size.width-100)/4)
            .heightIs(20);

            
            UILabel * lab2 = [[UILabel alloc]init];
            lab2.text = @"待收货";
            lab2.textAlignment = 1;
            lab2.font = [UIFont systemFontOfSize:15];
            [cell.contentView addSubview:lab2];
            
            lab2.sd_layout
            .topSpaceToView(but2,0)
            .leftEqualToView(but2)
            .widthIs((self.view.frame.size.width-100)/4)
            .heightIs(20);

            
            UILabel * lab3 = [[UILabel alloc]init];
            lab3.text = @"待评价";
            lab3.textAlignment = 1;
            lab3.font = [UIFont systemFontOfSize:15];
            [cell.contentView addSubview:lab3];
            
            lab3.sd_layout
            .topSpaceToView(but3,0)
            .leftEqualToView(but3)
            .widthIs((self.view.frame.size.width-100)/4)
            .heightIs(20);

            
            
        }
        if (indexPath.row==1) {
            cell.imageView.image=[UIImage imageNamed:@"我的订单.png"];
            cell.textLabel.text=@"我的订单";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    if (indexPath.section==1) {

        cell.imageView.image=[UIImage imageNamed:@"兑换.png"];
        cell.textLabel.text=@"胎币兑换";
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }
    if (indexPath.section==2) {
        if (indexPath.row==0) {
            cell.imageView.image=[UIImage imageNamed:@"优惠券.png"];
            cell.textLabel.text=@"我的优惠券";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
        if (indexPath.row==1) {
            cell.imageView.image=[UIImage imageNamed:@"我的碳币.png"];
            cell.textLabel.text=@"我的胎币";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    if (indexPath.section==3) {
        if (indexPath.row==0) {
            cell.imageView.image=[UIImage imageNamed:@"在线客服.png"];
            cell.textLabel.text=@"在线客服";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
        if (indexPath.row==1) {
            cell.imageView.image=[UIImage imageNamed:@"意见反馈.png"];
            cell.textLabel.text=@"意见反馈";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    cell.textLabel.textColor=[UIColor blackColor];
    cell.textLabel.font=[UIFont systemFontOfSize:17];

    return cell;
}

@end
